<script lang="ts" setup>
import useStore from '@/store'
import HomePanel from './home-panel.vue'
import { apiLazy } from '@/utils/hooks'
// import homeSkeleton from './home-skeleton.vue'
import { defineAsyncComponent } from 'vue'
const homeSkeleton = defineAsyncComponent(() => import('./home-skeleton.vue'))
/*
vue2:
异步:
components:{
  xxx::()=>import('')
}
vue3:组合api
1:import { defineAsyncComponent } from 'vue'
2：调用defineAsyncComponent方法实现异步组件
const homeSkeleton = defineAsyncComponent(() => import('./home-skeleton.vue'))
*/

const { home } = useStore()
const target = apiLazy(home.homeHot)
// home.homeHot()
</script>
<template>
  <!-- ref:1:响应式数据创建 2：获取dom 3:获取组件的实例对象 -->
  <div ref="target">
    <HomePanel title="人气推荐" sub-title="人气爆款 不容错过">
      <transition name="fade">
        <ul ref="pannel" class="goods-list" v-if="home.homeHotList.length">
          <li v-for="item in home.homeHotList" :key="item.id">
            <RouterLink to="/">
              <img v-lazyImg="item.picture" alt="" />
              <p class="name">{{ item.title }}</p>
              <p class="desc">{{ item.alt }}</p>
            </RouterLink>
          </li>
        </ul>
        <homeSkeleton v-else></homeSkeleton>
      </transition>
    </HomePanel>
  </div>
</template>

<style scoped lang="less">
// 1:变量 @xxx:12px
// 2:嵌套
// 3：&:代表父级
// 4:混入

.goods-list {
  display: flex;
  justify-content: space-between;
  height: 426px;
  li {
    width: 306px;
    height: 406px;
    .hoverShadow();
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
    }
    .desc {
      color: #999;
      font-size: 18px;
    }
  }
}
</style>
